<template>
	<div class="system-role-container layout-padding">
		<div class="system-role-padding layout-padding-auto">
			<el-card shadow="hover" class="pageQueryBoxArea mb10">
				<el-form :model="state.param" :inline="true">
					<el-form-item label="时间选择">
						<el-date-picker v-model="state.param.dateTime" type="daterange" unlink-panels :shortcuts="shortcuts"
							format="YYYY/MM/DD" value-format="YYYY-MM-DD" range-separator="-" :disabled-date="disabledDate"
							start-placeholder="开始日期" end-placeholder="结束日期" />
					</el-form-item>
					<el-form-item label="关键字">
						<el-input v-model="state.param.keyword" placeholder="请输入会员ID/姓名/昵称/手机" clearable></el-input>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="search()">
							<el-icon>
								<ele-Search />
							</el-icon>
							搜 索
						</el-button>
					</el-form-item>
				</el-form>
			</el-card>
			<el-card shadow="hover" style="display: flex; flex-direction: column; flex: 1; height: inherit">
				<section style="display: flex; flex-direction: column; flex: 1; height: inherit">
					<el-table :data="state.tableData">
						<el-table-column label="ID" v-if="state.param.statistics === 1" prop="id" />
						<el-table-column label="头像" prop="cardItemName" />
						<el-table-column label="用户信息" prop="property" />
						<el-table-column label="直推数量" sortable />
						<el-table-column label="直推订单" sortable />
						<el-table-column label="直推订单金额" sortable />
						<el-table-column label="直推已提现金额" sortable />
						<el-table-column label="直推已提现次数" sortable />
						<el-table-column label="未提现金额" sortable />
						<el-table-column label="冻结中佣金" sortable />
						<el-table-column label="成为推广员时间" />
						<el-table-column label="上级推广人" />  
						<el-table-column label="操作" width="150">
							<template #default="scope">
								<section style="display: flex; align-items: center;">
									<el-link :underline="false" type="primary" @click="previewInfo(scope.row.id)">推广人</el-link>&emsp;
									<el-dropdown @command="handleCommand" style="display: flex; align-items: center;">
										<span> 更多<el-icon class="el-icon--right"><arrow-down /></el-icon>
										</span>
										<template #dropdown>
											<el-dropdown-menu>
												<el-dropdown-item command="1">推广订单</el-dropdown-item>
												<el-dropdown-item command="2">清除上级推广人</el-dropdown-item>
											</el-dropdown-menu>
										</template>
									</el-dropdown>
								</section>
							</template>
						</el-table-column>
					</el-table>
					<el-row justify="end">
						<el-col :span="24" class="flex-end-center">
							<el-pagination @size-change="onHandleSizeChange" @current-change="onHandleCurrentChange" class="mt15"
								:pager-count="5" :page-sizes="[10, 20, 30]" v-model:current-page="state.param.pageNum" background
								v-model:page-size="state.param.pageSize" layout="total, sizes, prev, pager, next, jumper"
								:total="state.total">
							</el-pagination>
						</el-col>
					</el-row>
				</section>
			</el-card>
		</div>	
		<CardDialog v-model="cardDialogVisble" :statistics="state.param.statistics" :id="state.param.rowId" />
	</div>
</template>

<script setup lang="ts" name="funCountup">
import {  onMounted, reactive, ref, defineAsyncComponent } from 'vue';
import { ArrowDown } from '@element-plus/icons-vue'
import CardDialog from '/@/views/analysis/card/components/CardDialog.vue' 

import type { storeNodeListData, channelListData } from "/@/types/order";
import { storeNodeList } from '/@/api/order';
// const CardDialog = defineAsyncComponent(() => import('/@/views/card/components/CardDialog.vue'))

const state = reactive({
	param: {
		type: 4,
		source: 0, // 0 门店 2 线上 //设置不了得值是哪个？
		mode: null, // 门店类型  null(默认) 全部 0 直营  1 加盟
		storeStatus:-1,
		nodeId: null, // 门店id
		// 销售渠道
		channel: null,
		status: null,
		cardType:-1,
		// 支付方式
		dateTime: [],
		startTime: "",
		endTime: "",
		timeInterval: 3,
		total: 0,
		keyword: "",
		pageNum: 1,
		pageSize: 10,
		change: 999,
		storeType: null as null | number,
		statistics: 1,
		rowId: -1
	},
	query: {
		orderSource: [
			{ value: 0, label: '门店订单' },
		],
		storeType: [
			{ value: null, label: '全部' },
			{ value: 0, label: '直营' },
			{ value: 1, label: '加盟' }
		],
		storeStatus:[
			{ value: -1, label: '全部' },
			{ value: 1, label: '正常' },
			{ value: 2, label: '闭店' },
			{ value: 3, label: '休息' }
		],
		staticticsCategory: [
			{ value: 1, label: '卡项销售' },
			{ value: 2, label: '卡项普及' },
			{ value: 3, label: '卡项消耗' },
			{ value: 4, label: '大数据画像' },
		],
		cardType: [
			{ value: -1, label: '全部' },
			{ value: 0, label: '疗程卡' },
			{ value: 1, label: '单次卡' },
			{ value: 2, label: '体验卡' },
		],
		storeList: [] as Array<storeNodeListData>,
		orderStatus: [
			{ value: null, label: '全部' },
			{ value: 4, label: '已服务' },
			{ value: 14, label: '已撤销' },
		],
		saleChannel: [] as Array<channelListData>,
		orderType:[
			{ value: 999, label: '全部订单' },
			{ value: 1, label: '换卡服务' },
			{ value: 2, label: '余卡服务' },
		]
	},
	loading: false,
	total: 0,
	tableData: [
		{
			id: 1,
			cardItemName: '测试',
			property: '属性名称',
			spec: '规格',
			salesVolume: '销量',
			cellPrice: '销售价格',
			cellRatio: '销售占比',
			notUsedPrice: '未消耗金额',
			notUsedRatio: '未消耗占比',
			popularizePeple: '普及人数',
			popularizeRatio: '普及率',
			holdPeple: '持有人数',
			holdRatio: '持有率',
			lossPeple: '流失人数',
			lossRatio: '流失率',
			serviceCount: '服务量',
			consume: '消耗业绩',
			averageMonth: '月平均',
			averagePeple: '人平均',
			price: '客单价',
			repurchaseCycle: '复购周期',
			serviceGoodRatio: '服务好评率',
			sexRatio: '男女比例',
			age: '年龄'
		}
	] as Array<any>
		
});

const disabledDate= (time: Date) => time.getTime() > Date .now();

const shortcuts = [
	{
		text: '本月',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.setDate(1))
		return [start, end]
		},
	},
	{
		text: '近一个月',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
		return [start, end]
		},
	},
	{
		text: '近三个月',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
		return [start, end]
		},
	},
	{
		text: '近半年',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.getTime() - 3600 * 1000 * 24 * 180)
		return [start, end]
		},
	},
	{
		text: '近一年',
		value: () => {
		const end = new Date()
		const start = new Date()
		start.setTime(start.getTime() - 3600 * 1000 * 24 * 365)
		return [start, end]
		},
	},
]

const handleCommand = () => {

}

/**
 * 获取门店列表
 * mode  null /全部   0直营  1加盟
 */
 const getStoreNodeList = async () => {
	const { results } = await storeNodeList({ mode: null, current: 1, size: 50 });
	let no1 = [{id:null,name:'全部'}]
	state.query.storeList = [...no1, ...results.records];
}



const cardDialogVisble = ref(false)
const defaultTime2: [Date, Date] = [
  new Date(2000, 1, 1, 12, 0, 0),
  new Date(2000, 2, 1, 8, 0, 0),
]

const search = () => {}

const handleSizeChange = () => {}
const handleCurrentChange = () => {}
const previewInfo = (id: number) => {
	// state.param.rowId = id
	// cardDialogVisble.value = true
}
// 页面加载时
onMounted(() => {
	getStoreNodeList()
});
</script>

<style scoped lang="scss">
:deep(.el-card__body) {
	display: flex;
	flex-direction: column;
	flex: 1;
	height: inherit;
	.el-table {
		flex: 1;
		.el-table__inner-wrapper::before {
			background: none !important;
		}
	}
}
</style>
